<?php
declare(strict_types=1);
namespace cms\love\admin\mvc_controller;

use cms\love\service\AppService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Psr\Http\Message\ResponseInterface;

/**
 * Class AppController
 * @package cms\love\admin\mvc_controller
 * @AutoController(prefix="mvc/love/admin_app")
 */
class AppController extends CommonController
{
    /**
     * @Inject()
     * @var AppService
     */
    protected AppService $appService;

    /**
     * @return ResponseInterface
     */
    public function retrieve(): ResponseInterface
    {
        return $this->template();
    }

    /**
     * @return ResponseInterface
     */
    public function create(): ResponseInterface
    {
        return $this->template([], 'form');
    }

    /**
     * @return ResponseInterface
     */
    public function detail(): ResponseInterface
    {
        $id = (int) $this->request->input('id', 0);
        $data = $this->appService->getDataById($id, true);
        return $this->template([
            'app' => $data->app,
            'data' => $data
        ]);
    }

    public function setting(): ResponseInterface
    {
        $id = (int) $this->request->input('id', 0);
        $data = $this->appService->getDataById($id, true);
        return $this->template([
            'data' => $data
        ]);
    }
}